<?php

if(!defined("INDEX"))
    die;
    
if(!check_post('login', 'password', 'password2', 'email'))
    throw new HackException();

// ----------------------------------------------------------------------------

try {

    $pw = trim($_POST['password']);
    $pw2 = trim($_POST['password2']);

    if($pw !== $pw2)
        throw new Exception(_('Password fields are not identical'));

    $auth = new Auth;

    $user = $auth->registerUser($_POST['login'], $_POST['password'], $_POST['email']);
    
    if($user instanceof User)
        $user = $auth->loginUser($_POST['login'], $_POST['password']);

    $smarty->assign('user', $user);

} catch (Exception $e) {

    $smarty->assign('errors', array($e->getMessage()));
}

// ---------------------------------------------------------------------------
